package com.shizhanzhe.zxbapp.widget;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.CountDownTimer;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.shizhanzhe.zxbapp.R;

import butterknife.ButterKnife;

/**
 * Created by zz9527 on 2019/5/6.
 */
public class pop extends PopupWindow {
    Activity context;
    TextView tv;
    public pop(Activity context) {
        this.context=context;
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contextView = inflater.inflate(R.layout.pop, null);
        this.setContentView(contextView);
        tv = contextView.findViewById(R.id.time);
        this.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        this.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        this.setFocusable(false);
        this.setOutsideTouchable(false);
        this.update();


        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(30000000);
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        this.setBackgroundDrawable(dw);
        // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
        // 设置SelectPicPopupWindow弹出窗体动画效果
    }
    public void showDown(View view) {
        CountDownTimer time = new CountDownTimer(5000, 1000) {
            @SuppressLint("SetTextI18n")
            @Override
            public void onTick(long millisUntilFinished) {
                tv.setClickable(false);
                tv.setText( "为防止刷量，"+millisUntilFinished / 1000+"秒后自动签到");
            }

            @Override
            public void onFinish() {
                dismiss();
                WindowManager.LayoutParams lp = context.getWindow().getAttributes();
                lp.alpha = 1f;
                context.getWindow().setAttributes(lp);
            }
        };
        time.start();
        WindowManager.LayoutParams lp = context.getWindow().getAttributes();
        lp.alpha = 0.4f;
        context.getWindow().setAttributes(lp);
        this.showAtLocation(view, Gravity.BOTTOM, 0, 50);

    }
}
